package com.itheima.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.dto.LogisticsPriceDTO;
import com.itheima.pojo.LogisticsPrice;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
@Mapper
public interface LogisticsPriceMapper extends BaseMapper<LogisticsPrice> {

    @Select("SELECT lp.*, lc.name AS logisticsCompanyName FROM tb_logistics_price lp " +
            "LEFT JOIN tb_logistics_company lc ON lp.logistics_company_id = lc.id " +
            "${ew.customSqlSegment}")
    Page<LogisticsPriceDTO> selectPageDto(Page<LogisticsPriceDTO> page,
                                          @Param(Constants.WRAPPER) Wrapper<LogisticsPrice> wrapper);

    @Select("SELECT lp.* FROM tb_logistics_price lp " +
            "WHERE lp.logistics_company_id = #{companyId} AND lp.is_del = 1")
    List<LogisticsPriceDTO> selectPricesByCompanyId(@Param("companyId") Integer companyId);

    /**
     * 批量插入价格
     * @param prices 价格列表
     * @return 插入数量
     */
    int batchInsert(@Param("list") List<LogisticsPrice> prices);
}